var pageNo=1;
/*var userid=getvl("userid");
var sid=getvl("sid");*/
/*var userids=getvl("userids");*/
   /*$(function(){
  if(userid!=""&&sid!=""){
  	  	chaxun(userid,sid);
  	  }else if(userids!=""){
  	  	//useryouhuiquan(userids);
  	  }else{
  	  	alert("异常");
  	  }
  });*/


function chaxun(userid,sid){
	$("#youhuiquan").html("");
	var youhuiquan="";
	$.ajax({
		url: urlcore + "/api/userCoupon/wxvaluevoucher?userId="+userid+"&shopid="+sid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {

				   	if(data.data.userCouponList!=null){
				   			$.each(data.data.xtuserCouponList, function(y,n) {
		var gmtDatetime = new Date(n.gmtDatetime).pattern("yyyy-MM-dd");
		var limit_time=new Date(n.limitTime).pattern("yyyy-MM-dd");
				youhuiquan+='<div class="public-jianxi"></div>'+
					                          
'<div class="m_main mid-width" onclick="quzhi('+n.id+',\''+n.couponname+'\')" id="1">'+
'    <div class="a_discount curr1" >'+
'        <ul class="a_content clearfix">'+
'            <!-- <li><img src="images/a_qianbao_hui.png"></li> -->'+
'            <li class="a_infor">'+
'                <h3>'+n.couponname+'</h3>'+
'                <h3>满'+n.limitMoney+'元使用</h3>'+
'            </li>'+
'            <li class="a_price1">'+
'                <p><span>￥</span>'+n.saveMoney+'</p>'+
'            </li>'+
'        </ul>'+
'        <div class="a_time1">'+
'            <p>有效期'+gmtDatetime+'至'+limit_time+'</p>'+
'        </div>'+
'        <div class="youhuiquan_radio public-hide" id="youhui" >'+
'            <img src="images/public_radio_selcet.png">'+
'        </div>'+
'    </div>'+
'</div>';
         $("#youhuiquan").append(youhuiquan);
	});
				   	}
				  
		
				   	if(data.data.shuserCoupon!=null){
				   			$.each(data.data.shuserCoupon, function(y,n) {
		var gmtDatetime = new Date(n.gmtDatetime).pattern("yyyy-MM-dd");
		var limit_time=new Date(n.limitTime).pattern("yyyy-MM-dd");
				 youhuiquan+='<div class="public-jianxi"></div>'+
					                          
'<div class="m_main mid-width" onclick="quzhi('+n.id+',\''+n.couponname+'\')" id="1">'+
'    <div class="a_discount curr1" >'+
'        <ul class="a_content clearfix">'+
'            <!-- <li><img src="images/a_qianbao_hui.png"></li> -->'+
'            <li class="a_infor">'+
'                <h3>'+n.couponname+'</h3>'+
'                <h3>满'+n.limitMoney+'元使用</h3>'+
'            </li>'+
'            <li class="a_price1">'+
'                <p><span>￥</span>'+n.saveMoney+'</p>'+
'            </li>'+
'        </ul>'+
'        <div class="a_time1">'+
'            <p>有效期'+gmtDatetime+'至'+limit_time+'</p>'+
'        </div>'+
'        <div class="youhuiquan_radio public-hide" id="youhui" >'+
'            <img src="images/public_radio_selcet.png">'+
'        </div>'+
'    </div>'+
'</div>';
         $("#youhuiquan").append(youhuiquan);
	});
				   	}
			
			$(function(){
				  var hideClassName = "public-hide";
				 $(".m_main").click(function(){
        //a_discount curr1
       $(".m_main").each(function(){
         first($(this)).addClass("curr1");
         alert("选中")
          $(this).find(".youhuiquan_radio").addClass(hideClassName);
       });
       first($(this)).removeClass("curr1");
       $(this).find(".youhuiquan_radio").removeClass(hideClassName);

       function first($this){
        return $this.find(":first");
       }
    });
			});
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
}

//salert(sessionStorage.getItem("youhuiid"));

  useryouhuiquan();
function useryouhuiquan() {
	$("#youhuiquan").html("");
	$.ajax({
		url: urlcore + "/api/userCoupon/selectAllUserCoupon2?coupntid="+sessionStorage.getItem("youhuiid"),
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
			//	alert("@@@@"+JSON.stringify(data.data));
				   if(data.data!=null){				  
				$.each(data.data, function(y,n) {
	var gmtDatetime = new Date(n.coupon.gmtDatetime).pattern("yyyy-MM-dd");
	var limit_time=new Date(n.coupon.limitTime).pattern("yyyy-MM-dd");
					var youhuiquan='<div class="public-jianxi"></div>'+
'<div class="m_main mid-width" onclick="quzhi('+n.id+',\''+n.coupon.couponname+'\')" id="1">'+
'    <div class="a_discount curr1" >'+
'        <ul class="a_content clearfix">'+
'            <!-- <li><img src="images/a_qianbao_hui.png"></li> -->'+
'            <li class="a_infor">'+
'                <h3>'+n.coupon.couponname+'</h3>'+
'                <h3>满'+n.coupon.limitMoney+'元使用</h3>'+
'            </li>'+
'            <li class="a_price1">'+
'                <p><span>￥</span>'+n.coupon.saveMoney+'</p>'+
'            </li>'+
'        </ul>'+
'        <div class="a_time1">'+
'            <p>有效期'+gmtDatetime+'至'+limit_time+'</p>'+
'        </div>'+
'        <div class="youhuiquan_radio public-hide" id="youhui" >'+
'            <img src="images/public_radio_selcet.png">'+
'        </div>'+
'    </div>'+
'</div>';
         $("#youhuiquan").append(youhuiquan);
	});
			$(function(){
				  var hideClassName = "public-hide";
				 $(".m_main").click(function(){
        //a_discount curr1
       $(".m_main").each(function(){
         first($(this)).addClass("curr1");
         //alert("选中")
          $(this).find(".youhuiquan_radio").addClass(hideClassName);
       });
       first($(this)).removeClass("curr1");
       $(this).find(".youhuiquan_radio").removeClass(hideClassName);

       function first($this){
        return $this.find(":first");
       }
       
    });
			});
			}

			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
}
      //localStorage.removeItem('userinfo');
    sessionStorage.removeItem('names');
    sessionStorage.removeItem('ytypeId');
function  quzhi(ytypeId,names){
	   if(ytypeId!=''){
	   	
	   	
	    sessionStorage.setItem("names"+getvl("id"),names);
	    sessionStorage.setItem("ytypeId"+getvl("id"),ytypeId);
	    
	    sessionStorage.setItem(getvl("id"),getvl("id"));
	    
	    
	    alert(sessionStorage.getItem('orderid'+getvl("id")));
	    
	    
	//window.location.href="11.2.0dingdantijiao.html?userid="+userid+"&idss="+idss+"&ytypeId="+ytypeId+"&names="+names
	   }else{
	   	  alert("错误");
	   }
}
